package com.leyou.item.service;

import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecificationService {


    @Autowired
    private SpecGroupMapper specGroupMapper;

    @Autowired
    private SpecParamMapper specParamMapper;

    public List<SpecGroup> queryGroupsByBid(Long cid) {

            SpecGroup specGroup = new SpecGroup();
                specGroup.setCid(cid);

        return specGroupMapper.select(specGroup);

    }

    public List<SpecParam> querySpecParams(Long gid, Long cid,Boolean searching) {
        SpecParam specParam = new SpecParam();
        specParam.setGroupId(gid);
        specParam.setCid(cid);
        specParam.setSearching(searching);
        return specParamMapper.select(specParam);
    }

    public List<SpecGroup> querySpecsByCid(Long cid) {
        //查询规格参数组
        List<SpecGroup> groups = this.queryGroupsByBid(cid);

        groups.forEach(g->{
            //查询组内参数
            g.setParams(querySpecParams(g.getId(),null,null));
        });
        return groups;
    }
}
